#!/usr/bin/env python
# coding=utf-8
# 设置代理模拟登录人人网

from urllib.request import HTTPHandler,ProxyHandler,Request,build_opener,HTTPCookieProcessor
from http.cookiejar import CookieJar
from urllib.parse import urlencode


# 增加代理，本例代理不能用已注释取消代理
# opener = build_opener(HTTPHandler(),
#                       HTTPCookieProcessor(CookieJar()),
#                       ProxyHandler(proxies={"http":"http://123.55.102.9:9999",
#                                             "https":"https://123.44.44.44:8000"}))

opener = build_opener(HTTPHandler(),
                      HTTPCookieProcessor(CookieJar()),
                      )

url = "http://www.renren.com/ajaxLogin/login?1=1&uniqueTimestamp=20201142252890"
headers = {"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36",
           "Referer":"http://www.renren.com/"}

data = {"email": "abc",
"icode": "",
"origURL": "http://www.renren.com/home",
"domain": "renren.com",
"key_id": "1",
"captcha_type": "web_login",
"password": "494854863afc203477307a3fc13790e148e9a3c7410df0354e8df6dab86bb034",
"rkey": "39b392090c635431e86ef76d46f31f40",
"f": ""}

# data为二进制b'email=abc&icode=&origURL=http%3A%2F%2Fwww.renren.com%2Fhome&dom
print(urlencode(data).encode("utf-8"))
request = Request(url,urlencode(data).encode("utf-8"),headers=headers)
resp = opener.open(request)
print(resp.read().decode("utf-8"))